<template>
  <div id="home">
    <button @click="fullScreen">全屏显示</button>
    <div v-for="(value, key, index) in citys" :key="index">
      <h3>{{key}}</h3>
      <ul>
        <li v-for="li in value" :key="li.id">{{li.name}}</li>
      </ul>
    </div>
  </div>
</template>

<script>

export default {
  name: 'Home',
  data() {
    return {
      citys: {}
    }
  },
  created() {
    this.$http.get('http://elm.cangdu.org/v1/cities?type=group').then(res => {
      // var arr = []
      // for(var key in res.data) {
      //   arr.push(key)
      // }
      // arr.sort()
      // var obj = {}
      // arr.forEach((item) => {
      //   obj[item] = res.data[item]
      // })
      // this.citys = obj

      var obj = {}
      Object.keys(res.data).sort().forEach((item) => {
        obj[item] = res.data[item]
      })
      this.citys = obj
    })
  },

  methods: {
    fullScreen() {
      let box = document.getElementById('home')
      
      if(box.requestFullscreen) {
        box.requestFullscreen()
      } else if(box.mozRequestFullscreen) {
        box.mozRequestFullscreen()
      } else if(box.msRequestFullscreen) {
        box.msRequestFullscreen()
      } else if(box.webkitFullscreen) {
        box.webkitFullscreen()
      }
    }
  }
}
</script>
<style lang="scss" scoped>
#home{
  background-color: #fff;
}
  ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    // justify-content: space-between;
  }
  li{
    flex-basis: 22%;
    font-size: 12px;
    border: 1px solid #333;
    text-align: center;
    line-height: 30px;
    border-radius: 4px;
    margin: 10px 5px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
</style>
